<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>
        Document
        </title>
    </head>
    <body>
        <div id="app">
            <p>输入倍数：<input v-model="multiple" type="number" step="1" /></p>
            <p>无关测试值：<input v-model="test" type="number" step="1" /></p>
            <p>methods数组倍数求和：{{ mSum() }}</p>
            <p>computed数组倍数求和：{{ cSum }}</p>
    </div>
        <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
        <script>
        const app = new Vue({
                el: "#app",
            data:{
                    arr:[1, 2, 3],
                    multiple:1,
                    test:1
            },
            methods:{
                    mSum() {
                        let sum = 0;
                        for (let i = 0; i < this.arr.length; i++) {
                            sum += this.multiple * this.arr[i];
                    }
                    return sum;
                }
            },
            computed:{
                    cSum() {
                        let sum = 0;
                        for (let i = 0; i < this.arr.length; i++) {
                            sum += this.multiple * this.arr[i];
                    }
                    return sum;
                }
            }
        });
    </script>
</body>
</html>